<style>
  #admin-generator-configure .layui-form-label {
    width: 130px
  }

  #admin-generator-configure .layui-input-block {
    margin-left: 160px;
  }
</style>
<div class="layui-fluid layui-anim admin-anim" id="admin-generator-configure" lay-title="生成配置">
  <div class="layui-row admin-container">
    <div class="layui-card">
      <div class="layui-card-body" style="padding: 15px;">
        <form class="layui-form" action="" lay-filter="generator-configure-form">
          <div class="layui-form-item admin-hide">
            <label class="layui-form-label admin-form-item-require">ID：</label>
            <div class="layui-input-block">
              <input type="text" name="id" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">作者名称：</label>
            <div class="layui-input-block">
              <input type="text" name="author" autocomplete="off" maxlength="20" lay-verify="required"
                     class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">基础包名：</label>
            <div class="layui-input-block">
              <input type="text" name="basePackage" autocomplete="off" maxlength="50"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">entity包名：</label>
            <div class="layui-input-block">
              <input type="text" name="entityPackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">service包名：</label>
            <div class="layui-input-block">
              <input type="text" name="servicePackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">serviceImpl包名：</label>
            <div class="layui-input-block">
              <input type="text" name="serviceImplPackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">mapper包名：</label>
            <div class="layui-input-block">
              <input type="text" name="mapperPackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">mapperXml包名：</label>
            <div class="layui-input-block">
              <input type="text" name="mapperXmlPackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label admin-form-item-require">controller包名：</label>
            <div class="layui-input-block">
              <input type="text" name="controllerPackage" autocomplete="off" maxlength="20"
                     lay-verify="required" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">是否去除表前缀：</label>
            <div class="layui-input-block">
              <input type="radio" name="isTrim" value="1" lay-filter="isTrim" title="是" checked="">
              <input type="radio" name="isTrim" value="0" lay-filter="isTrim" title="否">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">表前缀：</label>
            <div class="layui-input-block">
              <input type="text" name="trimValue" autocomplete="off" maxlength="20" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item" shiro:hasPermission="generator:configure:update">
            <div class="layui-input-block">
              <button class="layui-btn" lay-submit="" lay-filter="generator-configure-form-submit">保存配置
              </button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

<script data-th-inline="javascript">
  layui.use(['admin', 'form'], function () {
    var $              = layui.$,
        admin          = layui.admin,
        form           = layui.form,
        $view          = $('#admin-generator-configure'),
        $trimValue     = $view.find('input[name="trimValue"]'),
        $trimValueItem = $trimValue.parents('.layui-form-item');

    var config = [[${config}]];

    form.render();
    initFormValue();

    form.on("radio(isTrim)", function (data) {
      if (data.value === '1') {
        trimValueItemShow();
      } else {
        trimValueItemHide();
      }
    });

    function initFormValue() {
      form.val("generator-configure-form", {
        "id"                : config.id,
        "author"            : config.author,
        "basePackage"       : config.basePackage,
        "entityPackage"     : config.entityPackage,
        "mapperPackage"     : config.mapperPackage,
        "mapperXmlPackage"  : config.mapperXmlPackage,
        "servicePackage"    : config.servicePackage,
        "serviceImplPackage": config.serviceImplPackage,
        "controllerPackage" : config.controllerPackage,
        "isTrim"            : config.isTrim,
        "trimValue"         : config.trimValue
      });

      if (config.isTrim === '1') {
        trimValueItemShow();
      } else {
        trimValueItemHide();
      }
    }

    function trimValueItemShow() {
      $trimValueItem.show();
    }

    function trimValueItemHide() {
      form.val("generator-configure-form", {
        "trimValue": ''
      });
      $trimValueItem.hide();
    }

    form.on('submit(generator-configure-form-submit)', function (data) {
      if (admin.nativeEqual(data.field, config)) {
        admin.alert.warn('数据未作任何修改！');
        return false;
      }
      admin.post(ctx + 'generatorConfig/update', data.field, function (r) {
        admin.alert.success('修改成功');
      });
      return false;
    });
  });
</script>